#include <pthread.h>
#include <iostream>
#include <vector>
#include <string>
#include <unistd.h>
using namespace std;

class Task
{
public:
    void func()
    {
        cout << "任务完成" << endl;
    }

private:
};

class information
{
public:
    information(pthread_t pt, string& pthreadname)
        :_pt(pt)
        ,_pthreadname(pthreadname)
    {}

    pthread_t Gettid()
    {
        return _pt;
    }

    string getname()
    {
        return _pthreadname;
    }

private:
    pthread_t _pt;
    string _pthreadname;
};

class Result
{
public:
    Result(bool ret = true)
        :_ret(ret)
    {}

    bool getret()
    {
        return _ret;
    }

private:
    bool _ret;
};

class pthread
{

public:

    static void* Pthread_Run(void* args)
    {
        pthread* pr = reinterpret_cast<pthread*>(args);
        pr->task.func();

        Result* rs = new Result;
        pr->rets.push_back(rs);

        return rs;
    }

    void Create_Run(int pthreadnum)
    {
        for(int i=0; i<pthreadnum; i++)
        {
            string pthreadname("pthread--" + to_string(i));

            pthread_t tid;
            pthread_create(&tid, nullptr, Pthread_Run, this);

            vpt.emplace_back(tid,pthreadname);
            sleep(1);
        }
    }
    
    void GetInformation()
    {
        void *ret = nullptr;
        for(auto &e : vpt)
        {
            pthread_join(e.Gettid(), &ret);
            cout << e.getname() << "-" << reinterpret_cast<Result*>(ret)->getret() << endl;;
        }
    }

    ~pthread()
    {
        GetInformation();
        for(auto &e : rets)
        {
            delete e;
        }
    }
    
private:
    vector<information> vpt;
    vector<Result*> rets;
    Task task;
};

int main(int argc, char* argv[])
{

    if(argc != 2)
    {
        cout << "Usage: " << argv[0] << " " << "number" << endl;
        exit(1);
    }

    int pthreadnum = stoi(argv[1]);
    pthread pr;
    pr.Create_Run(pthreadnum);

    return 0;
}